<template>
  <div>
    <FilterTable ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'records'" :isSelectColumn="false" :onColumnsChange="columns => (this.columns = columns)">
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import { getDiscountDetails } from '@/api/omSale/OrderManagement/HeadquartersOrder/index.js';
import { dictionary } from '@/utils/dictMixin';
export default {
  data() {
    return {
      columns: this.createdTable(),
      fetchParams: {
        policyId: '',
        singleAmount: '',
        subsidyAmount:''
      },
      fetchApi: getDiscountDetails
    };
  },
  created() {
    this.fetchParams.policyId = this.rowData.policyId;
    this.fetchParams.singleAmount = this.rowData.singleAmount;
    this.fetchParams.subsidyAmount=this.rowData.subsidyAmount;
  },
  mixins: [dictionary],
  props: ['rowData'],
  methods: {
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '折扣规则名称',
          dataIndex: 'ruleName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '动力形式',
          dataIndex: 'powerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6008'),
          render: (p) => {
            return <span >{this.createDictText(p.row.powerType, '6008')}</span>;
          },
        },
        {
          title: '折扣种类',
          dataIndex: 'discountType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6032'),
          render: p => {
            return <span>{this.createDictText(p.row.discountType, '6032')}</span>;
          }
        },
        {
          title: '折扣计算方式',
          dataIndex: 'discountMethod',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6033'),
          render: p => {
            return <span>{this.createDictText(p.row.discountMethod, '6033')}</span>;
          }
        },
        {
          title: '折扣值',
          dataIndex: 'discountValue',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p, h) => {
            return <span>{p.row.discountMethod == 60331001 ? p.row.discountValue : p.row.discountValue + '%'}</span>;
          }
        },
        {
          title: '单车折扣金额',
          dataIndex: 'discountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣前单价',
          dataIndex: 'singleAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣后单价',
          dataIndex: 'afterDiscountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    closeDrawer(type) {
      this.$emit('close');
    }
  }
};
</script>
